﻿@model KR.TPMS.Entity.Common_MonitoringManage
@{
    Layout = null;
    ViewBag.Title = "Index";
}
<!doctype html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui"/>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">
        body {
            margin: 0;
            padding: 0;
        }
    </style>
    <script src="/Scripts/jQuery/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="/Scripts/ckplayer/ckplayer.js?t=@DateTime.Now.Ticks" charset="UTF-8"></script>
    <script type="text/javascript">
        jQuery.support.cors = true;
        var player = {};
        //页面参数
        var playOption = {
            type: "@Model.PlayType",
            videourl: "",
            requesturl: "@Model.RequestUrl",
            arg: null
        };
        //播放器设置
        var videoObject = {
            container: '#video', //容器的ID或className
            variable: 'player', //播放函数名称
            loaded: 'loadedHandler', //当播放器加载后执行的函数
            loop: true, //播放结束是否循环播放
            autoplay: true, //是否自动播放
            // poster: 'material/poster.jpg', //封面图片
            config: '', //指定配置函数
            debug: false, //是否开启调试模式
            //flashplayer: true, //强制使用flashplayer
            // drag: 'start', //拖动的属性
            live: true, //是否是直播
            seek: 0, //默认跳转的时间
            //mobileCkControls:true,//是否在移动端（包括ios）环境中显示控制栏
            //video:"http://192.168.1.136:10800/hls/stream_1/stream_1_live.m3u8"//视频地址
            video: "" //视频地址
        };

        function init() {
            try {
                var j = "@Html.Raw(Model.RequestJSON)";
                j = j.replace(/'/g, '"');
                playOption.arg = JSON.parse(j);
            } catch (e) {

            }
            StartPlay();
            StartHeartBeat();
        }

        function StartHeartBeat() {
            if (playOption.type == "1") {
                setTimeout(function() { hearBeart(); }, 50000);
            }
        }

        function hearBeart() {
            var url = playOption.requesturl +
                "/api/v1/touchchannelstream?channel=" +
                playOption.arg.channel +
                "&protocol=hls";
            $.getJSON(url);
            StartHeartBeat();
        }

        function StartPlay() {
            if (playOption.type == "1") {
                var url = playOption.requesturl +
                    "/api/v1/getchannelstream?channel=" +
                    playOption.arg.channel +
                    "&protocol=hls";
                $.getJSON(url,
                    function(json) {
                        playOption.videourl = playOption.requesturl + json.EasyDarwin.Body.URL;
                    });
            } else {
                playOption.videourl = "@Model.MonitoringManage_URL";
            }
            setTimeout("Play()", 1000);
        }
        function Play() {
            if (playOption.arg){
            var url = playOption.requesturl +
                           "/api/v1/touchchannelstream?channel=" +
                           playOption.arg.channel +
                           "&protocol=hls";
            $.getJSON(url);
            }
            try {

                if (playOption.videourl == "" || playOption.requesturl == playOption.videourl || playOption.videourl.length < 10) {
                    setTimeout("StartPlay()", 500);
                    return;
                }
                $.post("/Common/GetIfarm/IsExistVideo",
                    { url: encodeURIComponent(playOption.videourl) },
                    function(json) {
                        if (json.result) {
                            videoObject.video = playOption.videourl;
                            var player = new ckplayer(videoObject);
                        } else {
                            setTimeout("Play()", 500);
                        }
                    });
            } catch (e) {
            }
        }

        function loadedHandler() {
        }

        $(function() {
            init();
        });

    </script>
</head>
<body>
<div style="float: left; margin: 3px;">
@*    <script type="text/javascript" src="/Scripts/player/sewise.player.min.js?server=vod&type=m3u8&videourl=@Model.MonitoringManage_URL&autostart=true&starttime=0&lang=zh-cn&draggable=false&title=111&buffer=5&claritybutton=disable&skin=vodWhite&topbardisplay=disable"></script>*@
    <div id="video" style="width: 540px; height: 400px;">
        视频加载中...
    </div>

</div>
</body>
</html>
